package com.yifeng.repo.storage.redis.configure;

import com.yifeng.repo.storage.redis.client.JedisClient;
import com.yifeng.repo.storage.redis.RedisCacheWorker;
import com.yifeng.repo.storage.redis.RedisLockWorker;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by daibing on 2022/8/9.
 */
@Configuration
@ConditionalOnClass({RedisProperties.class})
@EnableConfigurationProperties(RedisProperties.class)
public class RedisConfiguration {
    private final RedisProperties properties;

    public RedisConfiguration(RedisProperties properties) {
        this.properties = properties;
    }

    @Bean(initMethod = "init", destroyMethod = "destroy")
    public JedisClient jedisClient() {
        return new JedisClient(properties);
    }

    @Bean
    public RedisCacheWorker redisCacheWorker(JedisClient jedisClient) {
        return new RedisCacheWorker(jedisClient);
    }

    @Bean
    public RedisLockWorker redisLockWorker(JedisClient jedisClient) {
        return new RedisLockWorker(jedisClient);
    }

}

